package com.usdt.web.controller.cp.salesTools;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.usdt.common.core.domain.R;
import com.usdt.system.domain.req.BatchTransferOutReqVO;
import com.usdt.system.domain.resp.BatchClueRespVO;
import com.usdt.system.domain.resp.BatchVisitRespVO;
import com.usdt.system.domain.resp.SalespersonRespVO;
import com.usdt.system.service.cp.BatchManagementService;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;

@RestController
@RequestMapping("/batchManagement")
@Slf4j
@Tag(name = "查重/批量转出")
public class BatchManagementController {
	
	@Autowired
	private BatchManagementService batchManagementService;

    @GetMapping("/clue")
    @Operation(summary ="根据手机号检测是否有线索")
    public R<List<BatchClueRespVO>> getClueByPhoneNumber(@Schema(description = "手机号")@RequestParam(value = "phoneNumber", required = true) String phoneNumber) {
    	
    	return R.ok(batchManagementService.getBatchClueByPhoneNumber(phoneNumber));
    }
    
    @GetMapping("/visit")
    @Operation(summary ="根据手机号检测是否有到访")
    public R<List<BatchVisitRespVO>> getVisitByPhoneNumber(@Schema(description = "手机号")@RequestParam(value = "phoneNumber", required = true) String phoneNumber) {
    	
    	return R.ok(batchManagementService.getVisitByPhoneNumber(phoneNumber));
    }
    
    @GetMapping("/salesperson")
    @Operation(summary ="获取业务员")
    public R<List<SalespersonRespVO>> salesperson() {
    	
    	return R.ok(batchManagementService.salesperson());
    }
    
    @GetMapping("/clue/page")
    @Operation(summary ="线索批量转出分页列表")
    public R<IPage<BatchClueRespVO>> batchClueTransferOutPage(
    		@Schema(description = "线索来源")@RequestParam(value = "source", required = false) String source,
    		@Schema(description = "业务员")@RequestParam(value = "userId", required = false) String userId,
    		@Schema(description = "部门id")@RequestParam(value = "deptId", required = false) String deptId,
    		@Schema(description = "页码")@RequestParam(value = "pageNum", required = true,defaultValue="1") Integer pageNum,
    		@Schema(description = "每页显示记录数")@RequestParam(value = "pageSize", required = true,defaultValue="10") Integer pageSize,
    		@Schema(description = "手机号")@RequestParam(value = "phoneNumber", required = false) String phoneNumber
    		) {
    	
    	return R.ok(batchManagementService.batchClueTransferOutPage(source,userId,deptId,phoneNumber,pageNum,pageSize));
    }
    
    @Operation(summary ="线索批量转出")
 	@PostMapping("/clue/batchTransferOut")
 	public R<Boolean> clueBatchTransferOut(
 			@RequestBody @Valid BatchTransferOutReqVO vo) {
     	
     	return R.ok(batchManagementService.clueBatchTransferOut(vo));
 	}
    
    @GetMapping("/visit/page")
    @Operation(summary ="到访批量转出分页列表")
    public R<IPage<BatchVisitRespVO>> batchVisitTransferOutPage(
    		@Schema(description = "线索来源")@RequestParam(value = "source", required = false) String source,
    		@Schema(description = "业务员")@RequestParam(value = "userId", required = false) String userId,
    		@Schema(description = "部门id")@RequestParam(value = "deptId", required = false) String deptId,
    		@Schema(description = "页码")@RequestParam(value = "pageNum", required = true,defaultValue="1") Integer pageNum,
    		@Schema(description = "每页显示记录数")@RequestParam(value = "pageSize", required = true,defaultValue="10") Integer pageSize,
    		@Schema(description = "手机号")@RequestParam(value = "phoneNumber", required = false) String phoneNumber
    		) {
    	
    	return R.ok(batchManagementService.batchVisitTransferOutPage(source,userId,deptId,phoneNumber,pageNum,pageSize));
    }
    
    @Operation(summary ="到访批量转出")
 	@PostMapping("/visit/batchTransferOut")
 	public R<Boolean> visitBatchTransferOut(
 			@RequestBody @Valid BatchTransferOutReqVO vo) {
     	
     	return R.ok(batchManagementService.visitBatchTransferOut(vo));
 	}
}
